/***************************************************************************
 *   mgpi_stddefs.h - Standard Includes & Type Definitions                 *
 *   Copyright (C) 2008 by cmaster.matso                                   *
 *   cmaster.matso@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef _STDDEFS_H
#define _STDDEFS_H

#ifdef __cplusplus
extern "C" {
#endif

#include <time.h>
#include <ctype.h>
#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#include "../../errors/src/mgpi_errors.h"

#ifdef WIN32
#include <windows.h>
#endif

#define MGPI_FALSE (0)															/** standard definition of boolean false */
#define MGPI_TRUE (!MGPI_FALSE)													/** standard definition of boolean true */

    typedef unsigned char MGPI_UCHAR;											/** standard unsigned char */
    typedef MGPI_UCHAR MGPI_BOOL;												/** standard boolean */
    typedef MGPI_UCHAR MGPI_BYTE;												/** standard byte */

#pragma pack(push, 1)

    enum MGPI_COORDS_UV {
        S, T, R, Q
    };																			/** standard texture coordinates */

    enum MGPI_COORDS_4 {
        X, Y, Z, W
    };																			/** standard vector components */

    typedef struct _tree {
        struct _tree *parent;
        struct _tree **children;
        int nchld;
        void *data;
    } tree_t;																	/** standard tree definition */

#pragma pack(pop)

    /**
     * Devides the given string according to the given number of delim. substrings.
     */
    int MGPI_API strstok(char *s, char *delim, int ndelim);

    /**
     * Returns a number of bytes in the stream given.
     */
    long MGPI_API fncbstrm(FILE *stream);

    /**
     * Loads a file of the given name to a bytes array.
     */
    MGPI_BYTE MGPI_API *fload(char *name);

    /**
     * Saves given byts array to the file of the given name.
     */
    int MGPI_API fsave(char *name, MGPI_BYTE *file_buffer, int len);

    /**
     * Creates a charactes array of a given length, initialized with zeros.
     */
    char MGPI_API *string(long length);

    /**
     * Creates a float3 vector.
     */
    float MGPI_API *vector3(float x, float y, float z);

    /**
     * Creates a float3x3 matrix.
     */
    float MGPI_API **matrix3(float *m);

    /**
     * Creates a float4 vector.
     */
    float MGPI_API *vector4(float x, float y, float z, float w);

    /**
     * Creates a float4x4 matrix.
     */
    float MGPI_API **matrix4(float *m);

    /**
     * Creates an array float3x3 matrix, initialized with zeros.
     */
    float MGPI_API *matrix3x3(void);

    /**
     * Creates an array float4x4 matrix, initialized with zeros.
     */
    float MGPI_API *matrix4x4(void);

    /**
     * Creates an array floatnxn matrix, initialized with zeros.
     */
    float MGPI_API *matrixnxn(int n);

    /**
     * Creates an array floatnxm matrix, initialized with zeros.
     */
    float MGPI_API *matrixnxm(int n, int m);

    enum MGPI_COORDS_MATRIX {
        M11, M12, M13, M14, M21, M22, M23, M24, M31, M32, M33, M34, M41, M42, M43, M44
    };                                                                          /** matrix indices definitions */

    MGPI_BOOL g_fState;
#define MGPI_STATE g_fState                                                     /** global state property */

#ifdef __cplusplus
}
#endif

#endif

